package util;

import winkyle.woodenfish.enums.ResultEnum;
import winkyle.woodenfish.model.vo.HttpResult;

/**
 * @author winkyle
 * @date 2018/06/22
 * @description 返回结果封装类
 */
public class ResultUtil{
	
	/**
	 * @description 请求成功有返回数据
	 * @param object 需返回的数据
	 * @return
	 */
	public static HttpResult<Object> success(Object object) {
		HttpResult<Object> httpResult = new HttpResult<Object>();
		httpResult.setCode(ResultEnum.SUCCESS.getCode());
		httpResult.setMsg("请求成功");
		httpResult.setBody(object);
		return httpResult;
	}

	/**
	 * @description 请求成功无返回数据
	 * @return
	 */
	public static HttpResult<Object> success() {	
		return success(null);
	}
	
	/**
	 * @description 请求失败
	 * @param code 错误码
	 * @param msg 错误信息
	 * @return
	 */
	public static HttpResult<Object> error(int code,String msg) {	
		HttpResult<Object> httpResult = new HttpResult<Object>();
		httpResult.setCode(code);
		httpResult.setMsg(msg);
		return httpResult;
	}
}
